package com.clkj.sunhelp.adapter.grid;

import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.bean.HelpProjKindItem;
import com.clkj.sunhelp.util.CommonUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/3/28.
 */

public class GridAdapterForJobDealKindChoose extends BaseAdapter {


    List<HelpProjKindItem> mJobDealKindList;
    Context mContext;
    LayoutInflater mLayoutInflater;

    int itemHeight;
    int itemWidth;

    public GridAdapterForJobDealKindChoose(Context context, List<HelpProjKindItem> jobDealKindList) {
        mContext = context;
        mJobDealKindList = jobDealKindList;
        mLayoutInflater = LayoutInflater.from(context);

        int actionBarHeight = 0;
        TypedValue tv = new TypedValue();
        if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, mContext.getResources().getDisplayMetrics());
        }

        int statusBarHeight = CommonUtil.getStatusBarHeight(mContext);
        int screenWidth = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
        int screenHeight = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();

        itemHeight = (screenHeight-actionBarHeight-statusBarHeight-3)/4;
        itemWidth = screenWidth/2;
    }

    @Override
    public int getCount() {
        return mJobDealKindList.size();
    }

    @Override
    public Object getItem(int i) {
        return mJobDealKindList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null)
        {
            view = mLayoutInflater.inflate(R.layout.grid_item_job_deal_kind,null);
            viewHolder = new ViewHolder();
            viewHolder.tvJobDealKind = (TextView) view.findViewById(R.id.tv_job_deal_kind);

            view.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        // Calculate ActionBar height


        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(itemWidth,itemHeight);
        viewHolder.tvJobDealKind.setLayoutParams(lp);

        viewHolder.tvJobDealKind.setText(mJobDealKindList.get(i).getItemName());


        return view;
    }


    static class ViewHolder{
        private TextView tvJobDealKind;









    }
}

